package com.sx.micowell.module.login

import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.mvvm.base.data.DataBindingConfig
import com.example.mvvm.until.LogUtils
import com.gyf.immersionbar.ImmersionBar
import com.miloyu.modelnet.response.TokenVO
import com.sx.micowell.BR
import com.sx.micowell.R
import com.sx.micowell.databinding.ActBindingPhoneBinding
import com.sx.micowell.framework.app.IntentKey
import com.sx.micowell.framework.app.MyActivity
import com.sx.micowell.framework.arouth.RouteManager
import com.sx.micowell.framework.arouth.RoutePath
import com.sx.micowell.framework.model.BindPhoneModel

/**
 * @Author: YY
 * @Time: 2021/9/11
 * @Describe 绑定手机号
 */
@Route(path = RoutePath.BIND_PHONE)
class BindingPhoneActivity : MyActivity<ActBindingPhoneBinding>() {

    @Autowired(name = IntentKey.DATA)
    @JvmField
    var token: TokenVO? = null

    lateinit var viewModel: BindPhoneModel

    override fun initViewModel() {
        super.initViewModel()
        viewModel = getActivityScopeViewModel(BindPhoneModel::class.java)
    }

    override fun initViewObservable() {
        super.initViewObservable()
        viewModel.sendCodeEvent.observe(this) {
            RouteManager.getInstance()
                .intentVerifyCode(viewModel.phoneNumber.get().toString(), viewModel.type, viewModel.openIDField.get().toString())
        }
    }

    override fun getDataBindingConfig(): DataBindingConfig {
        return DataBindingConfig(R.layout.act_binding_phone, BR.viewModel, viewModel)
    }

    override fun initView() {
        ImmersionBar.with(this).statusBarDarkFont(true)
            .fitsSystemWindows(true).init()
    }

    override fun initData() {
        if (token != null) {
            LogUtils.d("initData != null")
            viewModel.openIDField.set(token!!.openid)
        }
    }

}